//
//  PerformanceMercDetailTableViewCell.swift
//  kxf
//
//  Created by Mac on 2024/3/24.
//

import Foundation
import UIKit

class PerformanceMercDetailTableViewCell: UITableViewCell {
    
    var peizhiBlock:(()->())?
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .clear
        self.selectionStyle = .none
        initUI()
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(10)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var avatarImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_cell_avatar")
        
        return img
    }()
    lazy var nameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        
        return lab
    }()
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        
        return vi
    }()
    lazy var tradeNumLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var tradeNumLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "交易金额（元）"
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "贡献收益（元）"
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
    lazy var moneyLabel : YYLabel = {
        let lab = YYLabel()
        lab.textColor = .COLOR_TEXT_BLACK333
        lab.font = .systemFont(ofSize: 16, weight: .regular)
        
        return lab
    }()
}

extension PerformanceMercDetailTableViewCell{
    func updateUI(dict:NSDictionary) {
        nameLabel.text = "\(dict["channel"]as? String ?? "")"
//        tradeNumLabel.text = "\(dict["amount"]as? Double ?? 0.00)"
//        rebateLabel.text = "\(dict["fee"]as? Double ?? 0.00)"
        timeLabel.text = "时间：\(Date().timestampToDate(timestamp: TimeInterval((dict["createTime"]as? Int ?? 0)/1000),format: "yyyy-MM-dd HH:mm:ss"))"
        
        let moneyUnit = NSMutableAttributedString(string: "¥")
        let moneyString = NSMutableAttributedString(string: "\(dict["amount"]as? Double ?? 0.00)")
        moneyUnit.yy_font = .systemFont(ofSize: 11, weight: .regular)
        moneyString.yy_font = .systemFont(ofSize: 16, weight: .regular)
        moneyUnit.append(moneyString)
        moneyLabel.attributedText = moneyUnit
        
        if dict["channel"]as? String ?? "" == "微信支付"{
            avatarImgView.setImgLocal(imgName: "pay_type_wechat_icon")
        }else if dict["channel"]as? String ?? "" == "支付宝"{
            avatarImgView.setImgLocal(imgName: "pay_type_alipay_icon")
        }else if dict["channel"]as? String ?? "" == "首信易钱包"{
            avatarImgView.setImgLocal(imgName: "pay_type_sxy_icon")
        }else{
            avatarImgView.setImgLocal(imgName: "pay_type_unipay_icon")
        }
    }
}

extension PerformanceMercDetailTableViewCell{
    func initUI() {
        contentView.addSubview(whiteView)
        whiteView.addSubview(avatarImgView)
        whiteView.addSubview(nameLabel)
        
        whiteView.addSubview(timeLabel)
        whiteView.addSubview(moneyLabel)
//        whiteView.addSubview(lineView)
//        whiteView.addSubview(tradeNumLabel)
//        whiteView.addSubview(tradeNumLab)
//        whiteView.addSubview(rebateLabel)
//        whiteView.addSubview(rebateLab)
        
        setConstrait()
    }
    func setConstrait() {
        whiteView.snp.makeConstraints { make in
            make.left.top.width.equalToSuperview()
            make.height.equalTo(kFitWidth(73))
        }
        avatarImgView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(18))
            make.top.equalTo(kFitWidth(12))
            make.width.height.equalTo(kFitWidth(22))
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(avatarImgView.snp.right).offset(kFitWidth(3))
            make.centerY.lessThanOrEqualTo(avatarImgView)
            make.right.equalTo(kFitWidth(-75))
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(avatarImgView)
            make.bottom.equalTo(kFitWidth(-12))
        }
        moneyLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-18))
            make.centerY.lessThanOrEqualToSuperview()
        }
//        lineView.snp.makeConstraints { make in
//            make.left.equalTo(kFitWidth(124))
//            make.top.equalTo(kFitWidth(64))
//            make.width.equalTo(kFitWidth(0.4))
//            make.height.equalTo(kFitWidth(17))
//        }
//        tradeNumLabel.snp.makeConstraints { make in
//            make.left.equalTo(kFitWidth(8))
//            make.width.equalTo(kFitWidth(95))
//            make.top.equalTo(kFitWidth(77))
//            make.height.equalTo(kFitWidth(28))
//        }
//        tradeNumLab.snp.makeConstraints { make in
//            make.centerX.lessThanOrEqualTo(tradeNumLabel)
//            make.top.equalTo(tradeNumLabel.snp.bottom).offset(kFitWidth(2))
//        }
//        rebateLabel.snp.makeConstraints { make in
//            make.left.equalTo(lineView.snp.right).offset(kFitWidth(8))
//            make.centerY.lessThanOrEqualTo(tradeNumLabel)
//            make.width.equalTo(tradeNumLabel)
//        }
//        rebateLab.snp.makeConstraints { make in
//            make.centerX.lessThanOrEqualTo(rebateLabel)
//            make.centerY.lessThanOrEqualTo(tradeNumLab)
//        }
    }
}
